#include "StaticLinkList.h"
#include <gtest/gtest.h>

TEST(StaticLinkListTest, InitiallyEmpty) {
    StaticLinkList list;
    EXPECT_TRUE(list.Empty());
    EXPECT_EQ(list.Size(), 0);
}

TEST(StaticLinkListTest, InsertAndGet) {
    StaticLinkList list;
    list.Insert(1, 10);
    list.Insert(2, 20);
    list.Insert(2, 15); // 插入中间
    EXPECT_EQ(list.Get(1), 10);
    EXPECT_EQ(list.Get(2), 15);
    EXPECT_EQ(list.Get(3), 20);
    EXPECT_EQ(list.Size(), 3);
}

TEST(StaticLinkListTest, SetAndFind) {
    StaticLinkList list;
    list.Insert(1, 100);
    list.Insert(2, 200);
    list.Set(2, 300);
    EXPECT_TRUE(list.Find(100));
    EXPECT_TRUE(list.Find(300));
    EXPECT_FALSE(list.Find(200));
}

TEST(StaticLinkListTest, RemoveElement) {
    StaticLinkList list;
    list.Insert(1, 1);
    list.Insert(2, 2);
    list.Insert(3, 3);
    list.Remove(2);
    EXPECT_EQ(list.Get(1), 1);
    EXPECT_EQ(list.Get(2), 3);
    EXPECT_EQ(list.Size(), 2);
}

TEST(StaticLinkListTest, RemoveHeadAndTail) {
    StaticLinkList list;
    list.Insert(1, 11);
    list.Insert(2, 22);
    list.Insert(3, 33);
    list.Remove(1);  // 删除头部
    EXPECT_EQ(list.Get(1), 22);
    list.Remove(2);  // 删除尾部
    EXPECT_EQ(list.Get(1), 22);
    EXPECT_EQ(list.Size(), 1);
}

TEST(StaticLinkListTest, ClearList) {
    StaticLinkList list;
    for (int i = 0; i < 10; ++i)
        list.Insert(i + 1, i * 10);
    EXPECT_EQ(list.Size(), 10);
    list.Clear();
    EXPECT_TRUE(list.Empty());
}

TEST(StaticLinkListTest, ComplexInsertRemove) {
    StaticLinkList list;
    for (int i = 1; i <= 20; ++i)
        list.Insert(i, i);  // 1, 2, ..., 20
    EXPECT_EQ(list.Size(), 20);
    list.Remove(1);   // 删除第一个
    list.Remove(10);  // 删除中间的
    list.Remove(list.Size()); // 删除最后一个
    EXPECT_EQ(list.Size(), 17);
    EXPECT_TRUE(list.Find(5));
    EXPECT_FALSE(list.Find(1));
}

TEST(StaticLinkListTest, OverCapacityInsert) {
    StaticLinkList list;
    for (int i = 1; i <= 100; ++i) {
        list.Insert(i, i * 2);
    }
    EXPECT_EQ(list.Size(), 100);
    // 第 101 个插入应该抛异常或无效（需你实现中补充）
    EXPECT_ANY_THROW(list.Insert(101, 999));
}

// 运行所有测试用例
int main() {
    ::testing::InitGoogleTest();
    return RUN_ALL_TESTS();
}